package com.jz.community.moduleshopping.address.task;

import android.app.Activity;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;

import java.util.HashMap;

/**
 * Created by Target on 2018/5/9.
 */
public class DeleteAddressTask extends RxTask<String, Integer, Boolean> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public DeleteAddressTask(Activity activity,
                             ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        // 执行请求
        String result = OkHttpUtil.delete(Constant.DELETE_USER_ADDRESS_URL + ConverterUtils.toLong(params[0]), new HashMap<>());
        if (!Preconditions.isNullOrEmpty(result) && "true".equals(result)) {
            return true;
        }
        return false;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        ProgressDialogManager.dismissProgressDialog();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        ProgressDialogManager.showDialog(activity);
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

}
